package ruan_kao;

import java.util.ArrayList;

enum PieceColor {BLACK, WHITE}

class PiecePos {
    private int x;
    private int y;

    public PiecePos(int a, int b) {
        x = a;
        y = b;
    }

    public int getX() {
        return x;
    }

    public int getY() {
        return y;
    }
}

abstract class Piece {
    protected PieceColor m_color;
    protected PiecePos m_pos;

    public Piece(PieceColor color, PiecePos pos) {
        m_color = color;
        m_pos = pos;
    }

    public abstract void draw();//1
}

class BlackPiece extends Piece {
    public BlackPiece(PieceColor color, PiecePos pos) {
        super(color, pos);
    }

    public void draw() {
        System.out.println("draw a black piece");
    }
}

class WhitePiece extends Piece {
    public WhitePiece(PieceColor color, PiecePos pos) {
        super(color, pos);
    }

    public void draw() {
        System.out.println("draw a white piece");
    }
}

class PieceBoard {
    private static final ArrayList<Piece> m_arrayPiece = new ArrayList<>(); //2
    private String m_blackName;
    private String m_whiteName;

    public PieceBoard(String black, String white) {
        m_blackName = black;
        m_whiteName = white;
    }

    public void SetPiece(PieceColor color, PiecePos pos) {
        Piece piece = null;//3
        if (color == PieceColor.BLACK) {
            piece = new BlackPiece(color, pos);
            System.out.println(m_blackName + "在位置(" + pos.getX() + "," + pos.getY() + ")");
            piece.draw();//4
        } else {
            piece = new WhitePiece(color, pos);
            System.out.println(m_whiteName + "在位置(" + pos.getX() + "," + pos.getY() + ")");
            piece.draw();//5
        }
        m_arrayPiece.add(piece);
    }
}
